﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;

namespace liuzw.utils
{
    internal static class StringExtensions
    {
        [DebuggerStepThrough]
        public static bool IsMissing(this string value)
        {
            return string.IsNullOrWhiteSpace(value);
        }

        [DebuggerStepThrough]
        public static bool IsPresent(this string value)
        {
            return !string.IsNullOrWhiteSpace(value);
        }
        public static List<T> ToList<T>(this string str, string separator)
        {
            if (string.IsNullOrEmpty(str))
            {
                return null;
            }
            List<T> result = new List<T>();
            var arrayList = str.Split(new[] { separator }, StringSplitOptions.RemoveEmptyEntries);
            foreach (var item in arrayList)
            {
                var obj = (T)Convert.ChangeType(item, typeof(T));
                result.Add(obj);
            }
            return result;
        }
        public static List<T> ToList<T>(this string str, char split, Converter<string, T> convertHandler)
        {
            if (string.IsNullOrEmpty(str))
            {
                return new List<T>();
            }
            else
            {
                string[] arr = str.Split(split);
                T[] Tarr = Array.ConvertAll(arr, convertHandler);
                return new List<T>(Tarr);
            }
        }
    }
}
